#!/usr/bin/env python
# -*- coding: utf-8 -*-


import os.path
import urllib2

import cherrypy
from cherrypy.lib.static import serve_file


path   = os.path.abspath(os.path.dirname(__file__))
config = {
  'global' : {
    'server.socket_host' : '127.0.0.1',
    'server.socket_port' : 8008,
    'server.thread_pool' : 8
  },
  '/js' : {
    'tools.staticdir.on'  : True,
    'tools.staticdir.dir' : os.path.join(path, '..')
  }
}


class Root:
  
  @cherrypy.expose
  def index(self):
    return serve_file(os.path.join(path, 'testrunner.html'))
  
  @cherrypy.expose
  def proxy(self, url):
    request = urllib2.urlopen(url, timeout = 10)
    cherrypy.response.headers['X-Final-Url'] = request.geturl()
    return request.read()


if __name__ == '__main__':
  cherrypy.quickstart(Root(), '/', config)

  